﻿/* shipGunControl.cs
 *  Author: Richard Broker
 *  
 *  This file is part of Tame.
 *
 *  Tame is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  Tame is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Tame. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

/* Contains controlling information for all instances of shipGun */
namespace Tame.ShipStructure
{
    class shipGunControl
    {

        List<shipGun> gunList;
        private int gunLimit;

        public shipGunControl()
        {
            /* Set up gun stack */
            gunList = new List<shipGun>(5);
            gunLimit = 0;
            addGun(0);
            addGun(1);
            addGun(2);
            addGun(3);
            addGun(4);
        }

        public void addGun(int position)
        {
            if (gunList.Count < gunList.Capacity)
            {
                shipGun newShipGun = new shipGun(0);
                gunList.Insert(position, newShipGun);
            }
        }
        public void setGun(int gunNumber, int index)
        {
            if (gunList.Count > 0)
            {
                gunList[index].intialiseGun(gunNumber);
            }
        }


        public shipGun getGunAtIndex(int index)
        {
            return gunList[index];
        }

        public void removeGun()
        {
            if (gunList.Count > 0)
            {
                gunList.RemoveAt(gunList.Count);
            }
        }

        // TODO: cost, damage etc.
        public int getAggregateWeight()
        {
            int totalWeight = 0;

            if (gunList.Count > 0)
            {
                for (int i = 0; i < gunList.Count; i++)
                {
                    totalWeight += gunList[i].getGunWeight();
                }
            }
            return totalWeight;
        }

        public int getAggregateCost()
        {
            int totalCost = 0;

            if (gunList.Count > 0)
            {
                for (int i = 0; i < gunList.Count; i++)
                {
                    totalCost += gunList[i].getGunCost();
                }
            }
            return totalCost;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns>Damage * Fire Rate</returns>
        public int getAggregateDamgae()
        {
            int totalDamage = 0;

            if (gunList.Count > 0)
            {
                for (int i = 0; i < gunList.Count; i++)
                {
                    totalDamage += (gunList[i].getGunDamage() * (gunList[i].getFireRate()));
                }
            }
            return totalDamage;
        }

        public int getGunCount()
        {
            return gunList.Count;
        }

        public int getListMax()
        {
            return gunLimit;
        }

        public void setListMax(int a)
        {
            gunLimit = a;
        }

        public int getGunDamage(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getGunDamage();
            }
            return 0;
        }
        public int getGunFireRate(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getFireRate();
            }
            return 0;
        }
        public int getGunWeight(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getGunWeight();
            }
            return 0;
        }
        public int getGunCost(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getGunCost();
            }
            return 0;
        }
        public int getGunExoticCost(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getCrystals();
            }
            return 0;
        }
        public int getGunXPRequirement(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getXPRequirement();
            }
            return 0;
        }
        public string getGunRankPath(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getRankImagePath();
            }
            return null;
        }
        public int getGunType(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getGunType();
            }
            return 0;
        }
        public bool isPardusWeapon(int index)
        {
            if ((gunList.Count > 0) && (index < gunList.Count))
            {
                return gunList[index].pardusWeapon();
            }
            return false;
        }
        public string getGunImagePath(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getEquipmentImagePath();
            }
            return null;
        }
        public int getGunNumber(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getGunNumber();
            }
            return 0;
        }
        public int getRankValue(int index)
        {
            if (gunList.Count > 0)
            {
                return gunList[index].getRankValue();
            }
            return 0;
        }
        
    }
}
